package au.com.carboncycle.gb.engine.entities;

import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.util.EnumSet;

import org.apache.log4j.Logger;

import au.com.carboncycle.gb.engine.resources.Art;


public class HeroSprite extends Sprite {

	private static final Logger log = Logger.getLogger(HeroSprite.class);
	
	private enum HeroState {
		MOVING_LEFT,
		MOVING_RIGHT,
		MOVING_UP,
		MOVING_DOWN,
		DYING
	}
	
	private EnumSet<HeroState> heroState;
	
	public HeroSprite (Point startingPosition) {
		super(Art.player1Right, Art.player1Left, 0, startingPosition);
		this.heroState = EnumSet.noneOf(HeroState.class);
	}
	
	
	public void move (Point delta, WorldEntity world) {
		Point newPosition = (Point)this.position.clone();
		newPosition.translate(delta.x, delta.y);
		
		if (delta.x < 0) {
			heroState.add(HeroState.MOVING_LEFT);
			heroState.remove(HeroState.MOVING_RIGHT);
		} else if (delta.x > 0) {
			heroState.add(HeroState.MOVING_RIGHT);
			heroState.remove(HeroState.MOVING_LEFT);
		}
		
		Rectangle newBounds = calculateNewBoundsForMoveTo(newPosition);
		
			
		if (world.heroPositionAllowed(newBounds)) {
			this.position = newPosition;
			
			currPicIdx++;
			if (currPicIdx > maxPicIdx) {
				currPicIdx = 0;
			}
		}
		
		
	}


	@Override
	protected Image[][] getCurrentSheet() {
		return (heroState.contains(HeroState.MOVING_LEFT)) ? sheetLeftFacing : sheetRightFacing;
	}
	
}
